package com.xb.cloud.front.client;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.xb.cloud.front.common.FrontHomePageService;
import com.xb.cloud.gateway.client.Adapter;
import com.xb.cloud.gateway.client.AdapterContext;
import com.xb.cloud.gateway.client.RtnInfo;

/**
 * 
 * @ClassName: FrontHomePageAdapter
 * @Description:TODO
 * @author: 鲜备科技
 * @date: 2017年12月19日 下午6:30:04
 * 
 * @Copyright: 2017 www.xianbeitech.com Inc. All rights reserved.
 *
 */
@Component
public class FrontHomePageAdapter extends Adapter {
	@Autowired
	private FrontHomePageService frontHomePageService;

	/**
	 * 
	 * <p>
	 * Title: execute
	 * </p>
	 * <p>
	 * Description:获取H5首页数据
	 * </p>
	 * 
	 * @param urlPath
	 * @param isLogined
	 * @param bizInfo
	 * @param context
	 * @return
	 * @see com.xb.cloud.gateway.client.Adapter#execute(java.lang.String,
	 *      java.lang.Boolean, java.util.Map,
	 *      com.xb.cloud.gateway.client.AdapterContext)
	 */
	public RtnInfo execute(String urlPath, Boolean isLogined, Map<String, String> bizInfo, AdapterContext context) {
		RtnInfo rtnInfo = null;
		/**
		 * 获取广告位数据
		 */
		/**
		 * 在adapter实现类中，不建议adapter实现类自己捕获异常，如果后续做服务化，该adapter实现类会运行在网关的jvm中，
		 * 所有建议抛出运行异常，网关会统一捕获该地方的异常，并统一封装错误
		 */
		if (urlPath.toLowerCase().equals("/h5/homepage/ad")) {
			rtnInfo = frontHomePageService.getH5HomeADs(context.getCompanyId());
			// 获取推荐数据
		} else if (urlPath.toLowerCase().equals("/h5/homepage/recommend/fields")) {
			rtnInfo = frontHomePageService.getH5RecommendFields(context.getCompanyId());
		}

		return rtnInfo;
	}

	@Override
	public String getUrlMappingPath() {

		return "/h5/homepage/**";
	}

}
